<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
    1.第一初始的点为m=0 
    2.没次循环截取m到spaces[i]的值，同时把m = spaces[i] 
    3.最后我们加上最后一截字符s.slice(m,s.length)
    */
    var addSpaces = function (s, spaces) {
      let s1 = ''
      let m = 0
      for (let i = 0; i < spaces.length; i++) {
        s1 += s.slice(m, spaces[i])
        s1 += " "
        m = spaces[i]
      }
      s1 += s.slice(m, s.length)
      return s1
    };
    console.log(addSpaces(s = "icodeinpython", spaces = [1, 8]))
  </script>
</body>

</html>